//package com.wdd.myplatform.config.pulsar;
//
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.StringUtils;
//import org.apache.pulsar.client.api.Consumer;
//import org.apache.pulsar.client.api.Message;
//import org.apache.pulsar.client.api.MessageListener;
//import org.apache.pulsar.client.api.PulsarClientException;
//import org.springframework.stereotype.Component;
//
///**
// * @author wdd 2022/7/19
// */
//@Slf4j
//@Component
//public class PulsarMsgListener<T> implements MessageListener {
//
//    /**
//     * This method is called whenever a new message is received.
//     *
//     * <p>Messages are guaranteed to be delivered in order and from the same thread for a single consumer
//     *
//     * <p>This method will only be called once for each message, unless either application or broker crashes.
//     *
//     * <p>Application is responsible for acking message by calling any of consumer acknowledgement methods.
//     *
//     * <p>Application is responsible of handling any exception that could be thrown while processing the message.
//     *
//     * @param consumer the consumer that received the message
//     * @param message
//     */
//    @Override
//    public void received(Consumer consumer, Message message) {
//        try {
//            String key = message.getKey();
//            String data = new String(message.getData());
//            String topic = message.getTopicName();
//            if (StringUtils.isNotEmpty(data)) {
//                try{
//                    log.info("收到消息, topic:{}, key:{}, data:{}", topic, key, data);
//                }catch(Exception e){
//                    log.error("接收消息异常，topic:{}, key:{}, data:{}", topic, key, data, e);
//                }
//            }
//            consumer.acknowledge(message);
//        } catch (PulsarClientException e) {
//            e.printStackTrace();
//        }
//    }
//}
